package com.xxx.video.main.presenters;

import android.content.Context;

import androidx.annotation.NonNull;

import com.xxx.video.commen.beans.BaseBean;
import com.xxx.video.commen.presenters.BasePresenter;
import com.xxx.video.commen.utils.ResponseUtils;
import com.xxx.video.main.beans.DynamicInfoBean;
import com.xxx.video.main.beans.VideoDetailsCommentListBean;
import com.xxx.video.network.listeners.CommonResponseListener;
import com.xxx.video.network.utils.NetWorkUtils;

public class VideoDetailsCommentPresenter extends BasePresenter<IVideoDetailsCommentView> {

    public VideoDetailsCommentPresenter(@NonNull Context context, IVideoDetailsCommentView baseView) {
        super(context, baseView);
    }

    /**
     * get comment info
     *
     * @param page    page
     * @param videoId video id
     */
    public void getCommentInfo(int page, String videoId) {
        NetWorkUtils.getInstance().getCommentInfo(page, videoId, new CommonResponseListener<VideoDetailsCommentListBean>() {
            @Override
            public void onSuccess(VideoDetailsCommentListBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().initData2View(successOb);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {
                if (getBaseView() != null) {
                    getBaseView().showRootLayoutStatus(3);
                }
            }
        });
    }

    public void deleteComment(String fId, int position) {
        NetWorkUtils.getInstance().deleteComment(fId, new CommonResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean successOb, String result) {
                if (ResponseUtils.getInstance().isNoError(successOb)) {
                    if (getBaseView() != null) {
                        getBaseView().deleteCommentSuccess(position);
                    }
                }
            }

            @Override
            public void onFailure(Object failureObj) {
                if (getBaseView() != null) {
                    getBaseView().showRootLayoutStatus(3);
                }
            }
        });
    }
}
